package com.dq.domain.evaluation;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author liuhui
 * @date 2019/11/20 0020 13:41:44
 */
@Entity
@Data
@ApiModel("评价模板子项目")
public class EvaluationTemplateChild extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("评价模板")
    @ManyToOne
    protected EvaluationTemplate evaluationTemplate;

    @ApiModelProperty("标题")
    @NotBlank(message = "子项名称不能为空")
    protected String title;

    @ApiModelProperty("子项对应分数")
    @NotNull(message = "子项对应分数不能为空")
    protected Long score;

    @ApiModelProperty("后台展示排序")
    @NotNull(message = "排序不能为空")
    protected Long sort;

    public EvaluationTemplateChild() {
    }
    public EvaluationTemplateChild(@NotBlank String title, @NotNull Long score, @NotNull Long sort, EvaluationTemplate evaluationTemplate) {
        this.title = title;
        this.score = score;
        this.sort = sort;
        this.evaluationTemplate = evaluationTemplate;
    }

    @Data
    @ApiModel(value = "评价模板子项目视图")
    public static class Vo implements VO {
        @ApiModelProperty("评价模板子项id")
        protected Long id;

        @ApiModelProperty("评价标题")
        protected String title;

        @ApiModelProperty("评价分数")
        protected Long score;

        @ApiModelProperty("评价模板名称")
        protected String name;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.title =fmt(this.getTitle());
        vo.score = fmt(this.getScore());
        vo.name = fmt(this.getEvaluationTemplate().getName());
        return vo;
    }
    @Data
    @ApiModel(value = "评价模板子项目列表视图")
    public static class EvaluationTemplateChildList{
        @ApiModelProperty("子模版id")
        protected Long id;
        @ApiModelProperty("评价标题")
        protected String title;
        @ApiModelProperty("对应分数")
        protected Long score;
    }

    public EvaluationTemplateChildList toEvaluationTemplateChildList(){
        EvaluationTemplateChildList vo = new EvaluationTemplateChildList();
        vo.id = this.id;
        vo.title = this.title;
        vo.score = this.score;
        return vo;
    }
}
